package com.eatables.service;

import java.util.List;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eatables.dao.EatablesMasterDao;

public class EatablesGetHotelDetailsImpl extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5381402966545050667L;

	@SuppressWarnings("unchecked")
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		EatablesMasterDao masterDao = new EatablesMasterDao();
		String slno = request.getParameter("slno");
		String city = request.getParameter("city");
		List hotelData = masterDao.getHotelData(slno, city);
		request.setAttribute("data", hotelData);
		try {
			if (city == "chn" || city.equals("chn")) {
				getServletConfig().getServletContext().getRequestDispatcher(
						"/chennai/hotelDetails.jsp").forward(request, response);
			} else if (city == "ben" || city.equals("ben")) {
				getServletConfig().getServletContext().getRequestDispatcher(
						"/bengaluru/hotelDetails.jsp").forward(request,
						response);
			} else if (city == "kol" || city.equals("kol")) {
				getServletConfig().getServletContext().getRequestDispatcher(
						"/kolkata/hotelDetails.jsp").forward(request, response);
			} else if (city == "hyd" || city.equals("hyd")) {
				System.out.println("Forwarding to hyd hoteldetails page");
				getServletConfig().getServletContext().getRequestDispatcher(
						"/hyderabad/hotelDetails.jsp").forward(request,
						response);
			}
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// :TODO
		// pass this parameter to Service layer
		// get a bean or list of properties
		// pass these to JSP by setting to request paramater(s) or via beans

		/*
		 * try { getServletConfig().getServletContext().getRequestDispatcher(
		 * "/JSP/Demo.hello.jsp").forward(request,response);
		 * 
		 * } catch (ServletException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated
		 * catch block e.printStackTrace(); }
		 */

	}

}
